package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by xxx on 2018/1/25.
 */

public class BaseMediaAdapter extends BaseAdapter{

    private Context context;
    private List<String> dateStr;
    private int  Tag = 0; // 0 视频 1图片
    public BaseMediaAdapter(Context context,List<String> dateStr,int Tag){
        this.context = context;
        this.dateStr = dateStr;
        this.Tag = Tag;
    }

    @Override
    public int getCount() {
        return dateStr!=null?dateStr.size()+1:1;
    }

    @Override
    public Object getItem(int position) {
        return dateStr.get(position-1);
    }

    @Override
    public long getItemId(int position) {
        return position-1;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.media_view,parent,false);
            holder = new ViewHolder();
            holder.thubImg = convertView.findViewById(R.id.thubImg);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }


        if (Tag == 0){
            if (dateStr!=null&&dateStr.size()>0){
                if (position == dateStr.size()&&dateStr.size()==1){
                  //  holder.thubImg.setImageResource(R.mipmap.icon_addbutton);
                    holder.thubImg.setVisibility(View.GONE);
                }else{
                    Glide.with(context).load(dateStr.get(position)).thumbnail(0.1f).into(holder.thubImg);
                }
            }else{
                holder.thubImg.setImageResource(R.mipmap.icon_addbutton);
            }
        }else{

            if (dateStr!=null&&dateStr.size()>0){
                if (position==dateStr.size()){
                    if (dateStr.size()<9){
                        holder.thubImg.setVisibility(View.VISIBLE);
                        holder.thubImg.setImageResource(R.mipmap.icon_addbutton);
                    } else
                        holder.thubImg.setVisibility(View.GONE);
                }else{
                    Glide.with(context).load(dateStr.get(position)).thumbnail(0.1f).into(holder.thubImg);
                }
            }else{
                holder.thubImg.setImageResource(R.mipmap.icon_addbutton);
            }
        }

//        if (position==0){
//            holder.thubImg.setImageResource(R.mipmap.icon_addbutton);
//        }else{
//            Log.e("fileStr",dateStr.get(position-1));
//            Glide.with(context).load(dateStr.get(position-1)).thumbnail(0.1f).into(holder.thubImg);
//        }
        return convertView;
    }
    class ViewHolder{
        ImageView thubImg;
    }
}
